
<div class="row">
	<div class="col-lg-12">
    	<form method="get" action="index.php">
    	 <div class="form-group input-group col-lg-4" style="float:left;" >
         	<input type="hidden" name="page" value="article">
            <input
            	 value="<?php  if(isset($_GET['txtKey'])) echo $_GET['txtKey'];?>"
            	 name="txtKey"
            	 type="text" 
                 class="form-control">
            <span class="input-group-btn">
            	<button  type="submit" class="btn btn-primary" type="button"><i class="fa fa-search"></i></button>
            </span>
         </div>
         </form>
       
         <div class="form-group input-group col-lg-3" style="float:right;" >
        <form method="get" action="index.php">
        	<input type="hidden" name="page" value="article">
            <p class="col-md-4">
            <input 
            	value="<?php echo $ipp; ?>"
            	type="text" 
                name="ipp"
                class="form-control">
             </p>   
            
            	<input type="submit" class="btn btn-primary" name="btnGui" type="button" value="Change">
          
         </form>   
         </div>
         

</div><!--.row-->
<form method="post" action="">
<div class="col-md-12">
	
        <div class="col-md-6 " style="margin-bottom:10px;" >
            
             <input type="submit" name="btnDel" value="Delete" class="btn btn-danger" >
         </div>
     
     <div class="col-md-6" style="margin-bottom:10px;" >
     	<a  class="btn btn-success pull-right" href="<?php echo $url; ?>index.php?page=article&action=add&form=1">Add new </a>
     </div>

</div><!-- /.row -->

     <div class="col-lg-12">
        <div class="table-responsive">
        	
            <table class="table table-bordered table-hover table-striped">
                <thead>
                    <tr>
                        <th>#</th>
                        <th><input id="check-all" type="checkbox"></th>
                        <th>Title</th>
                        <th>Category</th>
                        <th>User Created</th>
                        <th>User updated</th>
                        <th>Time created</th>
                        <th>Time updated</th>
                        <th>Display</th>
                        <th>Action</th>
                        
                    </tr>
                </thead>
                <tbody>
                    <?php
						//print_r($list_article); die;
						foreach($list_article as $key=>$item)
						{
							if(is_array($item))
							{
						
					?>
                   
                    <tr <?php if(($key%2==0)) echo "class='success'"; else echo "class='danger'";  ?>>
                        <td><?php echo $item['0'] ?></td>
                        <td><input class="check-all" type="checkbox" name="cbitem[]" value="<?php echo $item['id'];?>"></td>
                        <td class="col-md-3"><?php echo $item['title']; ?></td>
                        
                         <td style="text-align:center"><?php 
						    $sql_category="select * from tb_article_category where id=".$item["parentid"];
							$category=$lib->selectone($sql_category);
							if($category->title=='') echo "-"; else echo $category->title;
							
						?></td>
                        <td style="text-align:center"><?php 
						    $sql_usercreated="select * from tb_user where id=".$item["userid_created"];
							$usercreated=$lib->selectone($sql_usercreated);
							if($usercreated->username=='') echo "-"; else echo $usercreated->username;
							
						?></td>
                        <td style="text-align:center"><?php 
						    $sql_userupdate="select * from tb_user where id=".$item["userid_updated"];
							$userupdate=$lib->selectone($sql_userupdate);
							if($userupdate->username=='') echo "-"; else echo $userupdate->username;
							
						?></td>
                        <td><?php
							if($item['created'] != '0000-00-00 00:00:00') 
								echo gmdate('H:i d/m/Y', strtotime($item['created']) + 7*3600);
							else echo '-';
						 ?></td>
                        <td><?php
							 if($item['updated'] != '0000-00-00 00:00:00') 
								echo gmdate('H:i d/m/Y', strtotime($item['updated']) + 7*3600);
							else echo '-';
						 ?></td>
                     
                        <td  class="status">
                        	<!-- <form method="get" action="index.php">
                            	<input type="hidden" name="page" value="article">
                                <input type="hidden" name="action" value="display">
                                <input type="hidden" name="id" value="<?php //echo $item['id']; ?>">
                                <input class="btn-xs btn-primary" type="submit" name="btn" value="Change">
                             </form>-->
                            
                            <?php 
								if($item['publish']==1) echo "<i class='glyphicon glyphicon-ok'></i>";  
								
								if($item['publish']==0) echo "<i class='glyphicon glyphicon-lock'></i>";
							?>
                             
                        </td>
                       
                        <td class="action-f col-md-1" style="text-align:center;">
                        	<a 
                            	href="<?php echo $url; ?>index.php?page=article&action=del&id=<?php echo $item['id'] ?>"
                                onClick="return confirm('Do you want to delete this record ?')"
                                >
                            	<i class="glyphicon glyphicon-remove"></i>
                            </a>
                            
                            <a href="<?php echo $url; ?>index.php?page=article&action=edit&form=1&id=<?php echo $item['id'] ?>">
                            	<i class="glyphicon glyphicon-pencil"></i>
                            </a>
                            
                        </td>
                    </tr>
                   
                    <?php
							}
					   }
					?>
                   
                </tbody>
            </table>
            <div class="pagination"><?php $lib->viewpage($link); ?></div>
        </div>
    </div><!-- /.col-md-12 -->
</form>    
</div>
<!-- /.row -->

<script>
$(document).ready(function(e) {
 	/* ================ #CHECK-ALL =================== */
	$('#check-all').click(function(){
		
		if($(this).prop('checked')){
			$('.check-all').prop('checked', true).parent().parent().find('td').addClass('select');
		}
		else{
			$('.check-all').prop('checked', false).parent().parent().find('td').removeClass('select');
		}
	});
	$('.check-all').click(function(){
		if($(this).prop('checked') == false){
			$(this).parent().parent().find('td').removeClass('select');
			$('#check-all').prop('checked', false);
		}
		else{
			$(this).parent().parent().find('td').addClass('select');
		}
		if($('.check-all:checked').length == $('.check-all').length){
			$('#check-all').prop('checked', true);
		}
	});
});
	
</script>